package com.dbf.site.client.main.view;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;
import com.mvp4g.client.view.ReverseViewInterface;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
import com.sencha.gxt.widget.core.client.container.HasWidth;
import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.Viewport;
import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.Menu.MenuAppearance;

public class MainView extends Viewport  implements IMainView, ReverseViewInterface<IMainView.IMainPresenter> {
	
	private BorderLayoutContainer mainPanel;
	private HorizontalLayoutContainer centerPanel;
	private VerticalLayoutContainer vPanel;
	private VerticalLayoutContainer ePanel;
	private IMainView.IMainPresenter presenter;
	private SimpleContainer welcomeView;
	private Widget welcomeWidget;
	private SimpleContainer eastView;
	private Widget eastWidget;
	private SimpleContainer centerView;
	private Widget centerWidget;
//	private FlexTable table = new FlexTable();
	public MainView(){
		mainPanel = new BorderLayoutContainer();
		mainPanel.setSize("100%", "100%");
		mainPanel.setBorders(true);
		super.add(mainPanel);
		
		centerPanel = new HorizontalLayoutContainer();
		centerPanel.setSize("100%", "100%");
		BorderLayoutContainer.BorderLayoutData centerPanelData = new BorderLayoutContainer.BorderLayoutData(0.06);
		centerPanelData.setMargins(new Margins(4));
		mainPanel.setNorthWidget(centerPanel, centerPanelData);
		welcomeView = new SimpleContainer();
	    HorizontalLayoutContainer.HorizontalLayoutData hld01 = 
	    		new HorizontalLayoutContainer.HorizontalLayoutData(1, 1, new Margins(1));
	    centerPanel.add(welcomeView, hld01);
	    
	    
//	    FramedPanel container = new FramedPanel();
//	    container.setSize("100%", "100%");
//	    container.setHeaderVisible(false);
//	    container.setBodyStyle("background-color:#3892d5;");
	    vPanel = new VerticalLayoutContainer();
	    vPanel.setSize("100%", "100%");
	    vPanel.setBorders(true);
	    BorderLayoutContainer.BorderLayoutData vPanelData = new BorderLayoutContainer.BorderLayoutData(1);
		vPanelData.setMargins(new Margins(1));
		mainPanel.setCenterWidget(vPanel, vPanelData);
		centerView = new SimpleContainer();
	    VerticalLayoutContainer.VerticalLayoutData hld02 = 
	    		new VerticalLayoutContainer.VerticalLayoutData(1, 1, new Margins(1));
//	    table.getFlexCellFormatter().setColSpan( 0, 0, 2 );
//	    centerView.add(table);
	    vPanel.add(centerView, hld02);
	    
	    ePanel = new VerticalLayoutContainer();
	    ePanel.setSize("15%", "100%");
	    ePanel.setBorders(true);
	    BorderLayoutContainer.BorderLayoutData ePanelData = new BorderLayoutContainer.BorderLayoutData(0.13);
		ePanelData.setMargins(new Margins(1));
		eastView = new SimpleContainer();
		mainPanel.setEastWidget(ePanel, ePanelData);
		VerticalLayoutContainer.VerticalLayoutData eastVLayoutDate =
				new  VerticalLayoutContainer.VerticalLayoutData(1, 1, new Margins(1));
		ePanel.add(eastView, eastVLayoutDate);
		
		
	}
	@Override
	public void setPresenter(IMainPresenter presenter) {
		this.presenter = presenter;		
	}

	@Override
	public IMainPresenter getPresenter() {
		return this.presenter;
	}
	@Override
	public void setWelcomeView(Widget widget) {
		if (welcomeWidget != null) {
			welcomeWidget.removeFromParent();
		}
		welcomeView.add(widget);
		welcomeWidget = widget;
		mainPanel.forceLayout();
	}
	@Override
	public void setEastView(Widget widget) {
		if (eastWidget != null) {
			eastWidget.removeFromParent();
		}
		eastView.add(widget);
		eastWidget = widget;
		mainPanel.forceLayout();
	}
	@Override
	public void setMessageView(Widget widget) {
		if (centerWidget != null) {
			centerWidget.removeFromParent();
		}
		centerView.add(widget);
//		table.setWidget( 1, 0, widget.asWidget() );
		centerWidget = widget;
		mainPanel.forceLayout();
		
	}

}
